using System;
using System.Threading;
using System.Drawing;

namespace SJBotGame
{
	public class SJBotDraw
	{
		private Thread changeTitleDrawThread;
		//
		Graphics formGraphics;
		//
		SJBotTitleDraw titleDraw1;
		SJBotTitleDraw titleDraw2;
		//
		
		public SJBotDraw (Graphics formGraphics, SJBotTitleDraw titleDraw1, SJBotTitleDraw titleDraw2)
		{
			this.titleDraw1 = titleDraw1;
			this.titleDraw2 = titleDraw2;
			changeTitleDrawThread = new Thread(new ThreadStart(ChangeTitleDraw));
		}
		//
		public void StartChangeTitleDraw()
		{
			changeTitleDrawThread.Start();
		}
		public void Wait()
		{
			changeTitleDrawThread.Join();
		}
		private void ChangeTitleDraw()
		{
			EmptyArea();
			Thread.Sleep(10000);
		}
		private void EmptyArea()
		{
			Rectangle rect = GetFullRectangle(titleDraw1.Rect, titleDraw2.Rect);
			SolidBrush bgBrush = new SolidBrush(SJBotTitleDraw.bgColor);
            formGraphics.FillRectangle(bgBrush, rect);
            bgBrush.Dispose();
		}
		private Rectangle GetFullRectangle(Rectangle rect1, Rectangle rect2)
		{
			Rectangle rect = new Rectangle(Math.Min(rect1.Left, rect2.Left), Math.Min(rect1.Top, rect2.Top), 
			                               Math.Max(rect1.Right, rect2.Right) - Math.Min(rect1.Left, rect2.Left),
			                               Math.Max(rect1.Bottom, rect2.Bottom) - Math.Min(rect1.Top, rect2.Top));
			return rect;
			
		}
	}
}

